/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ValloyEditorUI.java
 *
 * Created on Mar 2, 2009, 10:17:36 PM
 */

package edu.ut.ece382c.valloy.ui;

import edu.mit.csail.sdg.alloy4whole.*;
/**
 *
 * @author vasr
 */
public class ValloyEditorUI extends javax.swing.JFrame {

    SimpleGUI asguiParent;
    /** The text editor. */

    ValloyInputController valloyInputCtrl = null;
    
    /** Creates new form ValloyEditorUI */
    public ValloyEditorUI() {
        initComponents();


    }

    public ValloyEditorUI(SimpleGUI asgui) {
        initComponents();
        asguiParent = asgui;
        if(asguiParent != null)
        {
            jLabel_ConnectedWithAlloy.setText("Connection with Alloy Succeeded");

        }

        jTabbedPane_ParserMode.setVisible(false);

    }

    public javax.swing.JTextArea GetAlloyTextArea()    {
        return AlloyTextArea;
    }

    public javax.swing.JTextArea GetValloyTextArea(){
        return ValloyTextArea;
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        ValloyTextArea = new javax.swing.JTextArea();
        jLabel_OpenedFileName = new javax.swing.JLabel();
        jButtonSaveValloyContext = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        AlloyTextArea = new javax.swing.JTextArea();
        Cmd_ExportToAlloy = new javax.swing.JButton();
        jButtonSave = new javax.swing.JButton();
        jLabelSaveAlloyFiileName = new javax.swing.JLabel();
        Cmd_Exit = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel_ConnectedWithAlloy = new javax.swing.JLabel();
        jTabbedPane_ParserMode = new javax.swing.JTabbedPane();
        jPanelLexerParser = new javax.swing.JPanel();
        jButton_LexerParser_CompileRunCommands = new javax.swing.JButton();
        jPanelStringParser = new javax.swing.JPanel();
        label1 = new java.awt.Label();
        Cmd_ExtractClassHierarchy = new javax.swing.JButton();
        cmd_GenerateAlloFunctions = new javax.swing.JButton();
        jButton_StringParserPredicates = new javax.swing.JButton();
        jButton_StringParser_ExecuteAll = new javax.swing.JButton();
        jButton_NonAlloy = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenuOpenFile = new javax.swing.JMenu();
        jMenuItem_OpenFile = new javax.swing.JMenuItem();
        jMenuItemSaveValloyContext = new javax.swing.JMenuItem();
        jMenuItemSaveAlloyContextAs = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem_FindModel = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Valloy > Alloy Converter");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Valloy Context", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        ValloyTextArea.setColumns(20);
        ValloyTextArea.setRows(5);
        jScrollPane1.setViewportView(ValloyTextArea);

        jLabel_OpenedFileName.setForeground(new java.awt.Color(0, 0, 255));
        jLabel_OpenedFileName.setText("[Select the file to process from the file menu]");
        jLabel_OpenedFileName.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jButtonSaveValloyContext.setText("Save Valloy Context...");
        jButtonSaveValloyContext.setEnabled(false);
        jButtonSaveValloyContext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveValloyContextActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
            .addComponent(jLabel_OpenedFileName, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonSaveValloyContext))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(331, 331, 331)
                        .addComponent(jLabel_OpenedFileName)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                .addComponent(jButtonSaveValloyContext))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Alloy Convertor", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        AlloyTextArea.setColumns(20);
        AlloyTextArea.setRows(5);
        jScrollPane2.setViewportView(AlloyTextArea);

        Cmd_ExportToAlloy.setText("Export to Alloy");
        Cmd_ExportToAlloy.setEnabled(false);
        Cmd_ExportToAlloy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Cmd_ExportToAlloyActionPerformed(evt);
            }
        });

        jButtonSave.setText("Save Alloy Context...");
        jButtonSave.setEnabled(false);
        jButtonSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveActionPerformed(evt);
            }
        });

        jLabelSaveAlloyFiileName.setForeground(new java.awt.Color(0, 0, 255));
        jLabelSaveAlloyFiileName.setText("[ ]");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabelSaveAlloyFiileName, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonSave)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(Cmd_ExportToAlloy))
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelSaveAlloyFiileName)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Cmd_ExportToAlloy)
                    .addComponent(jButtonSave)))
        );

        Cmd_Exit.setText("Close");
        Cmd_Exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Cmd_ExitActionPerformed(evt);
            }
        });

        jLabel1.setText("Version 1.0.0.8 a");

        jLabel_ConnectedWithAlloy.setText("Running as an Independent Application.");

        jButton_LexerParser_CompileRunCommands.setText("Execute Full Parser");
        jButton_LexerParser_CompileRunCommands.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_LexerParser_CompileRunCommandsActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelLexerParserLayout = new javax.swing.GroupLayout(jPanelLexerParser);
        jPanelLexerParser.setLayout(jPanelLexerParserLayout);
        jPanelLexerParserLayout.setHorizontalGroup(
            jPanelLexerParserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelLexerParserLayout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jButton_LexerParser_CompileRunCommands)
                .addContainerGap(582, Short.MAX_VALUE))
        );
        jPanelLexerParserLayout.setVerticalGroup(
            jPanelLexerParserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelLexerParserLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton_LexerParser_CompileRunCommands)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane_ParserMode.addTab("Lexer Parser", jPanelLexerParser);

        label1.setText("Extract > ");

        Cmd_ExtractClassHierarchy.setText("Classes");
        Cmd_ExtractClassHierarchy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Cmd_ExtractClassHierarchyActionPerformed(evt);
            }
        });

        cmd_GenerateAlloFunctions.setText("Functions");
        cmd_GenerateAlloFunctions.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmd_GenerateAlloFunctionsActionPerformed(evt);
            }
        });

        jButton_StringParserPredicates.setText("Predicates");
        jButton_StringParserPredicates.setEnabled(false);
        jButton_StringParserPredicates.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_StringParserPredicatesActionPerformed(evt);
            }
        });

        jButton_StringParser_ExecuteAll.setText("Execute Full  Parser");
        jButton_StringParser_ExecuteAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_StringParser_ExecuteAllActionPerformed(evt);
            }
        });

        jButton_NonAlloy.setText("Non-Alloy");
        jButton_NonAlloy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_NonAlloyActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelStringParserLayout = new javax.swing.GroupLayout(jPanelStringParser);
        jPanelStringParser.setLayout(jPanelStringParserLayout);
        jPanelStringParserLayout.setHorizontalGroup(
            jPanelStringParserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelStringParserLayout.createSequentialGroup()
                .addContainerGap(35, Short.MAX_VALUE)
                .addComponent(jButton_StringParser_ExecuteAll)
                .addGap(49, 49, 49)
                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Cmd_ExtractClassHierarchy)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmd_GenerateAlloFunctions)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_StringParserPredicates)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton_NonAlloy)
                .addGap(131, 131, 131))
        );
        jPanelStringParserLayout.setVerticalGroup(
            jPanelStringParserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelStringParserLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelStringParserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelStringParserLayout.createSequentialGroup()
                        .addGroup(jPanelStringParserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(Cmd_ExtractClassHierarchy)
                            .addComponent(cmd_GenerateAlloFunctions)
                            .addComponent(jButton_NonAlloy)
                            .addComponent(jButton_StringParserPredicates))
                        .addGap(1, 1, 1))
                    .addComponent(jButton_StringParser_ExecuteAll))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane_ParserMode.addTab("String Parser", jPanelStringParser);

        jMenuOpenFile.setText("File");

        jMenuItem_OpenFile.setText("Open File...");
        jMenuItem_OpenFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_OpenFileActionPerformed(evt);
            }
        });
        jMenuOpenFile.add(jMenuItem_OpenFile);

        jMenuItemSaveValloyContext.setText("Save Valloy Context As...");
        jMenuItemSaveValloyContext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSaveValloyContextActionPerformed(evt);
            }
        });
        jMenuOpenFile.add(jMenuItemSaveValloyContext);

        jMenuItemSaveAlloyContextAs.setText("Save Alloy Context As...");
        jMenuItemSaveAlloyContextAs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSaveAlloyContextAsActionPerformed(evt);
            }
        });
        jMenuOpenFile.add(jMenuItemSaveAlloyContextAs);

        jMenuBar1.add(jMenuOpenFile);

        jMenu2.setText("Edit");
        jMenu2.setEnabled(false);
        jMenuBar1.add(jMenu2);

        jMenu3.setText("Test Driver");

        jMenuItem_FindModel.setText("Find Models");
        jMenuItem_FindModel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem_FindModelActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem_FindModel);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane_ParserMode, javax.swing.GroupLayout.DEFAULT_SIZE, 742, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel_ConnectedWithAlloy, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)
                        .addGap(353, 353, 353)
                        .addComponent(Cmd_Exit)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane_ParserMode, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel_ConnectedWithAlloy)
                    .addComponent(Cmd_Exit))
                .addContainerGap())
        );

        jPanel2.getAccessibleContext().setAccessibleName("Alloy Context");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Cmd_ExtractClassHierarchyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cmd_ExtractClassHierarchyActionPerformed
        // TODO add your handling code here:
        if ( valloyInputCtrl != null)
            valloyInputCtrl.ExtractClassHierarchy(AlloyTextArea);
        
}//GEN-LAST:event_Cmd_ExtractClassHierarchyActionPerformed

    private void cmd_GenerateAlloFunctionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmd_GenerateAlloFunctionsActionPerformed
        // TODO add your handling code here:
        if ( valloyInputCtrl != null)
            valloyInputCtrl.GenerateAlloyFunctions(AlloyTextArea);
    }//GEN-LAST:event_cmd_GenerateAlloFunctionsActionPerformed

    private void Cmd_ExportToAlloyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cmd_ExportToAlloyActionPerformed
        // TODO add your handling code here:
        if ( valloyInputCtrl != null)
            valloyInputCtrl.ExportToAlloy(AlloyTextArea);
}//GEN-LAST:event_Cmd_ExportToAlloyActionPerformed

    private void Cmd_ExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cmd_ExitActionPerformed
        // TODO add your handling code here:
        //System.exit(0);
        this.setVisible(false);
    }//GEN-LAST:event_Cmd_ExitActionPerformed

    private void jMenuItem_OpenFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_OpenFileActionPerformed
        //Instantiate the ValloyInput controller
        if ( valloyInputCtrl == null)
            valloyInputCtrl = new ValloyInputController();
        //TODO: Needs to implement it on this end
        valloyInputCtrl.OpenValloyFile(ValloyTextArea,
            asguiParent );
        String message = "";
        if (valloyInputCtrl.ErrorData().length() > 0)
        {
            message = "ERROR: " + valloyInputCtrl.ErrorData();
        }
        else if(valloyInputCtrl.CurrentFileName().length() > 0)
        {
            message = valloyInputCtrl.CurrentFileName();
           jTabbedPane_ParserMode.setVisible(true);
           jButtonSave.setEnabled(true);
           jButtonSaveValloyContext.setEnabled(true);
           Cmd_ExportToAlloy.setEnabled(true);

        }

        jLabel_OpenedFileName.setText(message);

    }//GEN-LAST:event_jMenuItem_OpenFileActionPerformed

    private void jMenuItem_FindModelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_FindModelActionPerformed
        // TODO add your handling code here:
       DialogTestDriver openPopup = new DialogTestDriver(this, true);
        openPopup.setModal(true);
        openPopup.setVisible(true);

    }//GEN-LAST:event_jMenuItem_FindModelActionPerformed

    //String Parser extract Predicates
    private void jButton_StringParserPredicatesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_StringParserPredicatesActionPerformed
        if ( valloyInputCtrl != null)
            valloyInputCtrl.GenerateAlloyPredicates(AlloyTextArea);
    }//GEN-LAST:event_jButton_StringParserPredicatesActionPerformed

    //String Parser does a full conversion
    private void jButton_StringParser_ExecuteAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_StringParser_ExecuteAllActionPerformed
        if ( valloyInputCtrl != null)
            valloyInputCtrl.ParseClassesAndFunctions(AlloyTextArea);
    }//GEN-LAST:event_jButton_StringParser_ExecuteAllActionPerformed

    private void jButton_LexerParser_CompileRunCommandsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_LexerParser_CompileRunCommandsActionPerformed
        if ( valloyInputCtrl != null)
            valloyInputCtrl.ExecuterLexerParser(AlloyTextArea);
}//GEN-LAST:event_jButton_LexerParser_CompileRunCommandsActionPerformed

    private void jButton_NonAlloyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_NonAlloyActionPerformed
        // TODO add your handling code here:
        if ( valloyInputCtrl != null)
            valloyInputCtrl.ExtractNonConvertedData(AlloyTextArea);
    }//GEN-LAST:event_jButton_NonAlloyActionPerformed

    //Saves the Alloy context data
    private void jButtonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveActionPerformed
        // TODO add your handling code here:
        if ( valloyInputCtrl != null)
            valloyInputCtrl.SaveAlloyData(AlloyTextArea, jLabelSaveAlloyFiileName);
    }//GEN-LAST:event_jButtonSaveActionPerformed

    private void DoSaveAsValloyContext()
    {
        //Make sure you have data to save otherwise do nothing
        if( ValloyTextArea.getText().length() <= 0)
            return;

        //Instantiate the ValloyInput controller
        if ( valloyInputCtrl == null)
            valloyInputCtrl = new ValloyInputController();

        valloyInputCtrl.SaveValloyData(ValloyTextArea, asguiParent);
        String message = "";
        if (valloyInputCtrl.ErrorData().length() > 0)
        {
            message = "ERROR: " + valloyInputCtrl.ErrorData();
        }
        else if(valloyInputCtrl.CurrentFileName().length() > 0)
        {
            message = valloyInputCtrl.CurrentFileName();
           jTabbedPane_ParserMode.setVisible(true);
           jButtonSave.setEnabled(true);
           Cmd_ExportToAlloy.setEnabled(true);

        }

        jLabel_OpenedFileName.setText(message);

    }
    //Saves the Valloy context data
    private void jMenuItemSaveValloyContextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSaveValloyContextActionPerformed

        DoSaveAsValloyContext();
        
    }//GEN-LAST:event_jMenuItemSaveValloyContextActionPerformed

    private void jMenuItemSaveAlloyContextAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSaveAlloyContextAsActionPerformed
         //Instantiate the ValloyInput controller
        if ( valloyInputCtrl == null)
            valloyInputCtrl = new ValloyInputController();
        valloyInputCtrl.SaveAlloyData(AlloyTextArea, jLabelSaveAlloyFiileName);
    }//GEN-LAST:event_jMenuItemSaveAlloyContextAsActionPerformed

    private void jButtonSaveValloyContextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveValloyContextActionPerformed
        DoSaveAsValloyContext();
    }//GEN-LAST:event_jButtonSaveValloyContextActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ValloyEditorUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea AlloyTextArea;
    private javax.swing.JButton Cmd_Exit;
    private javax.swing.JButton Cmd_ExportToAlloy;
    private javax.swing.JButton Cmd_ExtractClassHierarchy;
    private javax.swing.JTextArea ValloyTextArea;
    private javax.swing.JButton cmd_GenerateAlloFunctions;
    private javax.swing.JButton jButtonSave;
    private javax.swing.JButton jButtonSaveValloyContext;
    private javax.swing.JButton jButton_LexerParser_CompileRunCommands;
    private javax.swing.JButton jButton_NonAlloy;
    private javax.swing.JButton jButton_StringParserPredicates;
    private javax.swing.JButton jButton_StringParser_ExecuteAll;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelSaveAlloyFiileName;
    private javax.swing.JLabel jLabel_ConnectedWithAlloy;
    private javax.swing.JLabel jLabel_OpenedFileName;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItemSaveAlloyContextAs;
    private javax.swing.JMenuItem jMenuItemSaveValloyContext;
    private javax.swing.JMenuItem jMenuItem_FindModel;
    private javax.swing.JMenuItem jMenuItem_OpenFile;
    private javax.swing.JMenu jMenuOpenFile;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanelLexerParser;
    private javax.swing.JPanel jPanelStringParser;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane_ParserMode;
    private java.awt.Label label1;
    // End of variables declaration//GEN-END:variables

}
